<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of subtask
 *
 * @author nathaniel.stevens.ad
 */
require_once 'model/subtaskModelClass.php';
require_once 'controller/commonController.php';

class subtaskControllerClass extends commonController {

    public function __construct($model) {
        $this->model = $model;
    }

    //ACTIONS******************************************************************* 
    /*
     * Returns the subtask details page
     */
    public function viewSubtaskDetailsRequest() {
        $this->model->string = $this->model->getSubtaskDetailsPage();
    }


    //****PROCESSING************************************************************
    /*
     * Main processing function
     */
    function processExistingSubtaskRequest() {
        if (isset($_POST['submit'])) {
            if (strcmp("Edit Subtask", $_POST['submit']) === 0) {
                $this->editExistingSubtaskRequest();
            } else if (strcmp("Delete Subtask", $_POST['submit']) === 0) {
                $this->processDeleteSubtaskRequest();
            } else if (strcmp("Deactivate", $_POST['submit']) === 0) {
                $this->processDeactivateSubtask();
            }  else if (strcmp("Activate", $_POST['submit']) === 0) {
                $this->processActivateSubtask();
            } else if (strcmp("Add Notes", $_POST['submit']) === 0) {
                $this->processAddNotesRequest();
            }  else if (strcmp("Submit Subtask Updates", $_POST['submit']) === 0) {
                $this->processUpdateSubtaskRequest();
            }else {
                $this->processChangeSubtaskStatusRequest();
            }
        }
    }

    /*
     * Returns the subtask details page with populated fields of an existing subtask
     */
    function editExistingSubtaskRequest() {
        $this->model->string = $this->model->getEditSubtaskPage();
    }
    
    /*
     * Processed the submitted information for an existing subtask (% complete, status, etc)
     */
    protected function processUpdateSubtaskRequest(){
        $url = $this->model->processUpdateSubtask();
        if ($url) {
            return header($url);
        } else {
            echo "error";
        }
    }

    /*
     * Delete a subtask
     */
    private function processDeleteSubtaskRequest() {
        $url = $this->model->processDeleteSubtask();
        if ($url) {
            echo header($url);
        } else {
            echo "Error deleting subtask";
        }
    }

    private function processDeactivateSubtask() {
        echo 'deactivate Subtask ';
        echo $this->model->ID;
    }

    private function processActivateSubtask() {
        echo 'activate Subtask ';
        echo $this->model->ID;
    }

    /*
     * Change the status of a subtask
     */
    private function processChangeSubtaskStatusRequest() {
        $url = $this->model->processChangeSubtaskStatus();
        if ($url) {
            echo header($url);
        } else {
            echo "Error changing subtask status";
        }
    }

}

?>
